H-Bridge 18 Click
H-Bridge 18 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
Click Library
- Author : Stefan Filipovic
- Date : Jan 2025.
- Type : SPI type
Software Support
Example Description
This example demonstrates the operation of the H-Bridge 18 Click board, which provides control over two DC motors using an H-Bridge driver. The application initializes the board and alternates between different motor states, including forward, reverse, coast, and braking, to demonstrate bidirectional motor control.
Example Libraries
- MikroSDK.Board
- MikroSDK.Log
- Click.HBridge18
Example Key Functions
- hbridge18_cfg_setup This function initializes Click configuration structure to initial values.
void hbridge18_cfg_setup(hbridge18_cfg_t *cfg)
H-Bridge 18 configuration object setup function.
H-Bridge 18 Click configuration object.
Definition hbridge18.h:238
- hbridge18_init This function initializes all necessary pins and peripherals used for this Click board.
err_t hbridge18_init(hbridge18_t *ctx, hbridge18_cfg_t *cfg)
H-Bridge 18 initialization function.
H-Bridge 18 Click context object.
Definition hbridge18.h:217
- hbridge18_default_cfg Click Default Configuration function.
err_t hbridge18_default_cfg(hbridge18_t *ctx)
H-Bridge 18 default configuration function.
- hbridge18_enable_device This function enables the H-Bridge 18 device by setting the sleep pin high.
void hbridge18_enable_device(hbridge18_t *ctx)
H-Bridge 18 enable device function.
- hbridge18_disable_device This function disables the H-Bridge 18 device by setting the sleep pin low.
void hbridge18_disable_device(hbridge18_t *ctx)
H-Bridge 18 disable device function.
- hbridge18_set_motor_state This function sets the motor state for the selected motor (coast, forward, reverse, brake low-side, or brake high-side).
err_t hbridge18_set_motor_state(hbridge18_t *ctx, uint8_t motor, uint8_t state)
H-Bridge 18 set motor state function.
Application Init
Initializes the logger and the H-Bridge 18 Click board. Configures the motor driver to the default settings, preparing it for operation.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( SPI_MASTER_ERROR ==
hbridge18_init( &hbridge18, &hbridge18_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define HBRIDGE18_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition hbridge18.h:201
@ HBRIDGE18_ERROR
Definition hbridge18.h:263
void application_init(void)
Definition main.c:41
#define MIKROBUS_POSITION_HBRIDGE18
Definition main.c:35
Application Task
Alternates motor states in a sequence to demonstrate different control functionalities. The motors are set to move forward and reverse, followed by coasting and braking, repeating the cycle continuously.
{
log_printf( &logger, " Motor 0: Forward\r\n" );
log_printf( &logger, " Motor 1: Reverse\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor 0: Coast\r\n" );
log_printf( &logger, " Motor 1: Brake LS\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor 0: Reverse\r\n" );
log_printf( &logger, " Motor 1: Forward\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor 0: Brake HS\r\n" );
log_printf( &logger, " Motor 1: Coast\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
#define HBRIDGE18_MOTOR_STATE_FORWARD
Definition hbridge18.h:169
#define HBRIDGE18_MOTOR_STATE_BRAKE_HS
Definition hbridge18.h:172
#define HBRIDGE18_MOTOR_STATE_COAST
H-Bridge 18 motor state setting.
Definition hbridge18.h:168
#define HBRIDGE18_MOTOR_STATE_REVERSE
Definition hbridge18.h:170
#define HBRIDGE18_MOTOR_1
Definition hbridge18.h:162
#define HBRIDGE18_MOTOR_STATE_BRAKE_LS
Definition hbridge18.h:171
#define HBRIDGE18_MOTOR_0
H-Bridge 18 motor selection setting.
Definition hbridge18.h:161
void application_task(void)
Definition main.c:77
Note
Ensure proper power supply (4.5V-32V, depending on motor specifications) and motor connections (motor 0: O1-O2; motor 1: O3-O4) before running the example.
Application Output
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Additional Notes and Information
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.